<?php

namespace app\admin\controller;

use app\admin\service\MonitorService;
use common\enum\ResultCode;
use hg\apidoc\annotation as Apidoc;
use support\Response;
use support\Container;

#[Apidoc\Title("系统监控")]
#[Apidoc\Sort(999)]
class MonitorController extends BaseController
{
    private MonitorService $service;

    public function __construct()
    {
        $this->service = Container::get(MonitorService::class);
    }

    #[Apidoc\Title("性能监控")]
    #[Apidoc\Url("admin/monitor/index")]
    #[Apidoc\Method("GET")]
    #[Apidoc\Returned(ref: [MonitorService::class, "getCpuInfo"])]
    #[Apidoc\Returned(ref: [MonitorService::class, "getMemoryInfo"])]
    #[Apidoc\Returned(ref: [MonitorService::class, "getDiskInfo"])]
    #[Apidoc\Returned(ref: [MonitorService::class, "getPhpInfo"])]
    public function index(): Response
    {
        $result = [
            'cpu' => $this->service->getCpuInfo(),
            'memory' => $this->service->getMemoryInfo(),
            'disk' => $this->service->getDiskInfo(),
            'php' => $this->service->getPhpInfo(),
        ];
        return $this->success($result, ResultCode::SUCCESS->getDescription());
    }
}